package com.taptech.doufu.ui.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.taptech.doufu.R;
import com.taptech.doufu.bean.TipInfo;
import com.taptech.doufu.listener.ResultTipListener;
import com.taptech.doufu.services.history.NovelHistoryView;
import com.taptech.doufu.ui.activity.base.DiaobaoBaseActivity;
import com.taptech.doufu.ui.view.TipDialog;

/**
 * Created by longsiyang on 16/4/6.
 */
public class DFHistoryActivity extends DiaobaoBaseActivity implements View.OnClickListener
{
    private FrameLayout framelayout;
    NovelHistoryView collec;
    private TextView tvClear;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dfhistory);
        initsView();
    }

    private void initsView()
    {
        tvClear = (TextView) findViewById(R.id.tv_dfhistory_clear);
        tvClear.setOnClickListener(this);
        framelayout = (FrameLayout) findViewById(R.id.frame_dfhistory);
        LayoutInflater mLi = LayoutInflater.from(this);
        View keepview = mLi.inflate(R.layout.activity_novel_history_list, null);
        collec = new NovelHistoryView(DFHistoryActivity.this, keepview);
        framelayout.addView(keepview);
    }

    @Override
    public void onClick(View v)
    {
        switch (v.getId())
        {
            case R.id.iv_dfhistory_back:
                DFHistoryActivity.this.finish();
                break;
            case R.id.tv_dfhistory_clear:
                TipInfo tipInfo = new TipInfo("警告", "请谨慎选择，点击确定将清空所有浏览记录", R.style.updateDialog, "确定", "取消", false);
                tipInfo.setTipListener(new ResultTipListener()
                {
                    @Override
                    public void resultBack(int flag, int type)
                    {
                        if (1 == flag) {
                            //确定是1
                            //清除全部
                            if (collec != null) {
                                collec.deleteAll();
                            }
                        }
                    }
                });
                TipDialog tipDialog = new TipDialog(this, R.style.updateDialog, tipInfo);
                tipDialog.show();
                break;
        }
    }
}
